package com.gsm.common.service;

import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 * @Description: java类作用描述
 * @Author: gaoshengmin
 * @CreateDate: 2020/2/8$ 14:35$
 * @UpdateUser: gaoshengmin
 * @UpdateDate: 2020/2/8$ 14:35$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class BaseService<T> {
    protected Specification<T> getSpec(String companyId){
       return new Specification<T>() {
            @Override
            public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                //根据企业Id进行查询
                return criteriaBuilder.equal(root.get("companyId").as(String.class), companyId);
            }
        };
    }
}
